package edu.xust.service.impl;

import edu.xust.config.Resource;
import edu.xust.config.Service;
import edu.xust.dao.AdminDao;
import edu.xust.entity.Admin;
import edu.xust.entity.AdminExample;
import edu.xust.mapper.AdminMapper;
import edu.xust.page.PageInfo;
import edu.xust.service.AdminService;
import sun.text.resources.cldr.mr.FormatData_mr;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @auther: zhangxin
 * @Description:
 */
@Service("adminService")
public class AdminServiceImpl implements AdminService {

    @Resource
    AdminDao adminDao;

    @Override
    public List<Admin> getAdminByPage(PageInfo pageInfo) throws Exception {
        return adminDao.getAdminByPage(pageInfo);
    }

    @Override
    public List<Admin> selectByExample(AdminExample example) {
        return adminDao.selectByExample(example);
    }

    @Override
    public Integer addAdmin(Admin admin) {
        admin.setRid(0);
        System.out.println(admin.getAdhead()+".......................");
        admin.setAdstatus(0);
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            date = sdf.parse(sdf.format(date));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        admin.setCreatetime(date);
        System.out.println(admin.toString());
        return adminDao.addAdmin(admin);
    }

    @Override
    public Integer editAdmin(Admin admin) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            date = sdf.parse(sdf.format(date));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        admin.setUpdatetime(date);
        System.out.println(admin.toString());
        return adminDao.editAdmin(admin);
    }

    @Override
    public Admin getAdminById(Integer adId) {
        return adminDao.getAdminById(adId);
    }


    @Override
    public Integer deleteAdminById(Integer adId) {
        return adminDao.deleteAdminById(adId);
    }
}
